package com.example.demo.common.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

/**
 * @author zhaiding
 */
@Component
public class ApplicationContextRegister implements ApplicationContextAware {

    private static ApplicationContext context;

    /**
     * 设置spring上下文
     *
     * @param applicationContext spring上下文
     */
    @Override
    public void setApplicationContext(@NonNull ApplicationContext applicationContext) {
        if (ApplicationContextRegister.context == null) {
            ApplicationContextRegister.context = applicationContext;
        }
    }

    public static ApplicationContext getContext() {
        return context;
    }
}